package com.example.myspringbootpj.service;

import com.example.myspringbootpj.entity.User;
import com.example.myspringbootpj.mapper.UserMapper;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.function.Supplier;

@Service
public class addUserService {

    private final UserMapper userMapper;

    @Autowired
    public addUserService(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    public boolean isUserIdExists(String userId) {
        int count = userMapper.countByUserId(userId);
        return count > 0;
    }

    public boolean register(User user) {
        try {
            int result = userMapper.add(user);
            return result > 0;
        } catch (Exception e) {
            // 捕获数据库异常，记录日志
            Logger logger = LoggerFactory.getLogger(addUserService.class);

            return false;
        }
    }
}

